/*!
\copyright  Copyright (c) 2025 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\ingroup    user_eq
\brief      Conversion of EQ paramtees between formats used by DSP and application

*/

#include "user_eq_params_conversion.h"

#include <q_format.h>

uint16 UserEq_ParamsConversionCutOffFrequencyFromQFormat(uint32 freq_in_q_format)
{
    uint32 freq = QFormat_ConvertQFormatToUint(22, (uint32)(freq_in_q_format * 0.75));
    freq = freq/3;

    return freq;
}

int16  UserEq_ParamsConversionGainFromQFormat(uint32 gain_in_q_format)
{
    uint32 gain = QFormat_ConvertQFormatToUint(18, (uint32)((int32)gain_in_q_format * 0.9375));

    return gain;
}

uint16 UserEq_ParamsConversionQFromQFormat(uint32 q_in_q_format)
{
    uint32 q = QFormat_ConvertQFormatToUint(20, q_in_q_format);

    return q;
}

uint32 UserEq_ParamsConversionGainToQFormat(int16 gain)
{
    /* value is Gain * 60, required format is Q 12.N (int32) */
    int32 wider_gain = gain;
    uint32 gain_in_q_format = QFormat_ConvertUintToQFormat(17, (uint32)((int32)wider_gain * 0.5333));

    return gain_in_q_format;
}